<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改</title>
	<script src="../../js/layui/layui.js"></script>
	<link rel="stylesheet" href="../../js/layui/css/layui.css" media="all" />
</head>
<body class="childrenBody">
	<form class="layui-form" lay-filter="formTest">
		<div class="layui-form-item">
			<div class="layui-form-item">
				<input type="hidden" name="id" />
				<label class="layui-form-label ">照片:</label>
				<button type="button" class="layui-btn" id="imgUpload">
					<i class="layui-icon">&#xe67c;</i>选择图片
				</button>
				<input type="hidden" name="name" value="" id="pid" />
				<br />
				<img src="" alt="图片去火星了" style="width:200px;margin: 20px 70px" id="imgFace" />
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图片地址</label>
			<div class="layui-input-inline">
				<input type="text" class="layui-input newsName" name="url"
					lay-verify="required" placeholder="请输入链接" />
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">权重</label>
			<div class="layui-input-inline">
				<input type="number" class="layui-input newsName" name="weight"
					lay-verify="required" placeholder="请输入权重" />
			</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
			</div>
		</div>
	</form>
	<script type="text/javascript">
	layui.use(['form','layer','upload'], function(){
		  var form = layui.form;
		  var layer = layui.layer;
		  var $ = layui.$;
		  var upload = layui.upload;
		  
		  //数据回显
		  var obj = JSON.parse(parent.json);
		  form.val("formTest",obj);
		  console.log(obj);
		  //图片回显
		  //var data=JSON.parse(sessionStorage.getItem("product"));
		  $("#imgFace").attr("src","../../../images/"+obj.name);
		  
		  form.on('submit(formDemo)', function(data){
			  $.post('http://localhost:8080/FiveClothes/banner/updateBanner',data.field,
					  function(res){
				  			var msg;
				  			if(res){
				  				msg="修改成功";
				  			}else{
				  				msg="修改失败";
				  			}
				  			layer.msg(msg, {
					  			  icon: 1,
					  			  time: 2000 //2秒关闭（如果不配置，默认是3秒）
					  			}, function(){
					  				var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
									parent.layer.close(index);//关闭弹出层
									 window.parent.location.reload();//刷新父页面
					  			}); 
				  },'json');
			  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
			});
		  
		  upload.render({
			  elem: '#imgUpload' //绑定元素
			  ,url:'http://localhost:8080/FiveClothes/uploadImg'
			  ,done: function(res){
			  //上传完毕回调
			  	$("#imgFace").attr("src","../../../images/"+res.remark);
			  //返回图片名字保存在隐藏域内
			 	$("#pid").val(res.remark);
			  	layer.msg("图片修改成功");
			  }
			  ,error: function(){
			  //请求异常回调
				 layer.msg("图片修改失败");
			  }
			});
		});
	</script>

	<!-- <script type="text/javascript" src="linksAdd.js"></script> -->
</body>
</html>